package com.orangelife.mobile.goodsrent.adapter;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.curry.android.adapter.FatherAdapter;
import com.curry.android.util.ImageDownloader;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.app.application.CurryApplication;
import com.orangelife.mobile.constants.Constant;
import com.orangelife.mobile.goodsrent.entity.GoodsInfo;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2015/12/18.
 */
public class GoodsRentOrderAdapter extends FatherAdapter<GoodsInfo> {
    private List<GoodsInfo> mGoodsInfoList;
    public GoodsRentOrderAdapter(List<GoodsInfo> goodsInfoList){
        this.mGoodsInfoList = goodsInfoList;
    }
    @Override
    public BaseAdapter setList(List<GoodsInfo> list) {
        this.mGoodsInfoList = list;
        return GoodsRentOrderAdapter.this;
    }

    @Override
    public int getCount() {
        return mGoodsInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return mGoodsInfoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView = LayoutInflater.from(CurryApplication.getInstance().getContext()).inflate(R.layout.item_lv_goodsrent_order_detaill,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        image.download(mGoodsInfoList.get(position).getGoodsLogo(), holder.ivGoodImg,
                ImageDownloader.ImageSize.IMAGE_SIZE_EXTRA_SMALL_RECTANGLE_JPG);
        holder.tvGoodsName.setText(mGoodsInfoList.get(position).getGoodName());
        holder.tvTotalNumber.setText("天数X"+ mGoodsInfoList.get(position).getDay());
        holder.tvMarkerPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        holder.tvMarkerPrice.setText(Constant.RMB_FLAG+mGoodsInfoList.get(position).getPrice());
        holder.tvUnitPrice.setText(Constant.RMB_FLAG+mGoodsInfoList.get(position).getPrice());
        return convertView;
    }

    class ViewHolder{
       @Bind(R.id.tvGoodsName)
       TextView tvGoodsName;
       @Bind(R.id.tvTotalNumber)
        TextView tvTotalNumber;
       @Bind(R.id.tvMarkerPrice)
        TextView tvMarkerPrice;
        @Bind(R.id.tvUnitPrice)
        TextView tvUnitPrice;
        @Bind(R.id.ivGoods)
        ImageView ivGoodImg;
        public ViewHolder(View v) {
            ButterKnife.bind(this, v);
        }
    }
}
